﻿<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>批量更改学生实习状态页</title>
		<script src="../../script/mui.min.js"></script>
		<link href="../../css/mui.min.css" rel="stylesheet"/>
		<link rel="stylesheet" type="text/css" href="../../css/base.css"/>
		<link rel="stylesheet" href="../../css/api.css">
		<link rel="stylesheet" href="../../css/CFNetPP_Base.css">
		<style type="text/css">
			html {
				height: 100%;
				background: #f3f5f7;
			}
			body {
				height: 100%;
				background: #f3f5f7;
			}
			.sxtype0 {
				font-size: 14px;
				float: right;
				margin-right: 37px;
				margin-bottom: 9px;
				top: 20px;
				width: 60px;
				height: 25px;
				text-align: center;
				color: #ff9a00;
				border: solid 1px #ff9a00;
				padding-top: 2px;
				border-radius: 5px;
			}
			.sxtype1 {
				font-size: 14px;
				float: right;
				margin-right: 37px;
				margin-top: 9px;
				width: 60px;
				height: 25px;
				text-align: center;
				color: #17b6ed;
				border: solid 1px #17b6ed;
				padding-top: 2px;
				border-radius: 5px;
			}
			.sxtype2 {
				font-size: 14px;
				float: right;
				margin-right: 37px;
				margin-bottom: 9px;
				top: 20px;
				width: 70px;
				height: 25px;
				text-align: center;
				color: #21bc3a;
				border: solid 1px #21bc3a;
				padding-top: 2px;
				border-radius: 5px;
			}
			.sxtype3 {
				font-size: 14px;
				float: right;
				margin-right: 37px;
				margin-bottom: 9px;
				top: 20px;
				width: 60px;
				height: 25px;
				text-align: center;
				color: #9357f2;
				border: solid 1px #9357f2;
				padding-top: 2px;
				border-radius: 5px;
			}
			.sxtype4 {
				font-size: 14px;
				float: right;
				margin-right: 37px;
				margin-bottom: 9px;
				top: 20px;
				width: 60px;
				height: 25px;
				text-align: center;
				color: #fd5722;
				border: solid 1px #fd5722;
				padding-top: 2px;
				border-radius: 5px;
			}
			.content_ul {
				margin-top: 96px;
				margin-bottom: 53px;
			}
			::-webkit-scrollbar {
				width: 0px
			}
			.studentbtn0 {
				top: 20px;
				right: 60px;
				padding: 0 10px;
			}
			.studentbtn1 {
				top: 20px;
				right: 60px;
				padding: 0 10px;
			}
			.studentbtn2 {
				top: 20px;
				right: 60px;
				padding: 0 10px;
			}
			.studentbtn3 {
				top: 20px;
				right: 60px;
				padding: 0 10px;
			}
			.studentbtn4 {
				top: 20px;
				right: 60px;
				padding: 0 10px;
			}
			.title_tag {
				line-height: 1em;
				padding: 10px 14px;
				padding-bottom: 0;
			}
			.title_tag_class {
				padding: 0 14px;
			}
			.droplist {
				position: fixed;
			}
			#dropdownPlanList {
				top: 75px;
			}
			#dropdownClassList {
				top: 145px;
			}
			.changeState .btn_submit {
				width: 70%;
				height: 40px;
				left: 50%;
				margin-top: 10px;
				transform: translate(-50%, 0);
				-webkit-transform: translate(-50%, 0);
				background: #ff9900;
				border-color: #ff9900;
				color: #fff;
				border: none;
			}
		</style>
	</head>
	<body>
		<div class="changeState">
			<div class="wraptop">
				<p class="title_tag base_grey base_tag_font" style="color: #666">
					实习计划
				</p>
				<div class="dropdown" id="dropdownPlanBtn">
					<span id="planName" class="className"></span>
					<span class="sanjiao"><img src="../../image/icon_sanjiao.png" alt=""></span>
				</div>
				<p class="title_tag base_grey base_tag_font title_tag_class" style="color: #666">
					班级
				</p>
				<div class="dropdown" id="dropdownClassBtn">
					<span id="className" class="className"></span>
					<span class="sanjiao"><img src="../../image/icon_sanjiao.png" alt=""></span>
				</div>
				<div class="mui-input-row mui-checkbox select_num" style="background-color: #f0f0f0;">
					<label class="base_tag_font base_light_gray"> 学生  已选择<span id="studentNum">0</span>人 </label>
					<input name="checkbox" value="Item 0" type="checkbox" id="checkdeAll">
				</div>
			</div>
			<div id="dropdownClassList" class=" droplist" hidden="hidden">
				<ul class="mui-table-view" id ="class_ul">
					<!-- <li class="mui-table-view-cell"><a href="#">物流长风实验班1</a></li>
					<li class="mui-table-view-cell"><a href="#">物流长风实验班2</a></li>
					<li class="mui-table-view-cell"><a href="#">物流长风实验班3</a></li>
					<li class="mui-table-view-cell"><a href="#">物流长风实验班4</a></li>
					<li class="mui-table-view-cell"><a href="#">物流长风实验班5</a></li> -->
				</ul>
			</div>
			<div id="dropdownPlanList" class=" droplist" hidden="hidden">
				<ul class="mui-table-view" id ="plan_ul">
					<!-- <li class="mui-table-view-cell"><a href="#">物流长风实验计划1</a></li>
					<li class="mui-table-view-cell"><a href="#">物流长风实验计划2</a></li>
					<li class="mui-table-view-cell"><a href="#">物流长风实验计划3</a></li>
					<li class="mui-table-view-cell"><a href="#">物流长风实验计划4</a></li>
					<li class="mui-table-view-cell"><a href="#">物流长风实验计划5</a></li> -->
				</ul>
			</div>
			<div class="emptya"></div>
			<div class="contents">
				<ul class="mui-table-view content_ul" id="checkboxes">
					<!-- <li class="mui-table-view-cell mui-checkbox mui-media">
					<a href="javascript:;">
					<img class="mui-media-object mui-pull-left" src="../../image/icon_man.png">
					<div class="mui-media-body top_15">
					uname
					<span class="sxtype2">
					跟岗实习
					</span>
					</div>
					</a>
					<input name="checkbox2" value="Item 1" type="checkbox" class="">
					</li> -->
				</ul>
				<div class="noSign" hidden="hidden" id="noData">
					<img src="../../image/icon_img.png" width="60%">
					<p class="font16 top_15 base_dark_grey" >
						暂无数据
					</p>
				</div>
				<div class="loadFailure" hidden="hidden" id="noNet">
					<img src="../../image/icon_img01.png" width="60%">
					<p class="" >
						数据加载失败
					</p>
					<p>
						请检查您的网络
					</p>
					<button type="button" class="mui-btn mui-btn-outlined" onclick="grabPlanData()">
						重新加载
					</button>
				</div>
			</div>
			<div class="bottom_btn">
				<button type="button" class="mui-btn btn_submit" id="submit" >
					提交
				</button>
			</div>
		</div>
		<script type="text/javascript" src="../../script/api.js"></script>
		<script src="../../script/jquery.min.js" type="text/javascript"></script>
		<script type="text/javascript" src="../../script/MD5.js"></script>
		<script type="text/javascript" src="../../script/requestTool.js"></script>
		<script>
			var classid = 'normal';
			var planid = '';
			var currentStudents;
			var pageType;
			var uid, jid;
			var allStudentClass = {
				class_id : 'normal',
				classname : '全部'
			};
			apiready = function() {
				// $('#dropdownPlanList').hide();
				// $('#dropdownClassList').hide();
				prepareData();
				grabPlanData();
			}
			//获取教师管理实习计划
			function grabPlanData() {
				showProgressFrame();
				var params = {
					uid : uid,
					jid : jid
				}
				cfnetppPOST(planListUrl, params, true, function(data, status) {
					if (status == 'success') {
						if (data.status == 1) {
							var planDatas = data.json;
							if (planDatas.constructor == Array && planDatas.length > 0) {
								$('#noData').hide();
								$('#noNet').hide();
								showFirstPlanData(planDatas[0]);
								var planHtmlString = '';
								for (var i = 0; i < planDatas.length; i++) {
									var planData = planDatas[i];
									planHtmlString += planHtmlStr(planData);
								}
								$('#plan_ul').html(planHtmlString);
								setupPlanClick();
							} else {
								$('#noData').show();
								$('#noNet').hide();
								api.hideProgress();
								api.toast({
									msg : '暂无数据'
								});
							}
						} else {
							$('#noData').show();
							$('#noNet').hide();
							api.hideProgress();
							api.toast({
								msg : '您当前尚未管理实习计划，无对应数据'
							});
						}
					} else {
						$('#noData').hide();
						$('#noNet').show();
						api.hideProgress();
						api.toast({
							msg : '获取实习计划列表失败'
						});
					}
				});
			}

			//获取教师管理班级数据
			function grabClassData() {
				var params = {
					uid : uid,
					jid : jid,
					plan_id : planid
				};
				if (classid != 'normal') {
					params['class_id'] = classid;
				}
				// alert(JSON.stringify(params));
				cfnetppPOST(planStudentsUrl, params, true, function(data, status) {
					api.hideProgress();
					if (status == 'success') {
						if (data.status == 1) {
							var jsonData = data.json;
							var classDatas = jsonData.bjname;
							if (classDatas.constructor == Array && classDatas.length > 0) {
								$('#noData').hide();
								$('#noNet').hide();
								if (classDatas[0].class_id != 'normal') {
									classDatas.unshift(allStudentClass);
									//插入“全部”选项
								}
								if (classid == 'normal') {
									showFirstClass(classDatas[0]);
								}
								//设置班级列表数据
								var classHtmlString = '';
								for (var i = 0; i < classDatas.length; i++) {
									var classData = classDatas[i];
									classHtmlString += classHtmlStr(classData);
								}
								$('#class_ul').html(classHtmlString);
								setupClassClick();
								//设置学生列表数据
								currentStudents = jsonData.studentarr;
								var studentsHtmlStr = '';
								for (var i = 0; i < currentStudents.length; i++) {
									var studentData = currentStudents[i];
									studentsHtmlStr += studentHtmlString(studentData, i);
								}
								$('#checkboxes').html(studentsHtmlStr);
								setupCheckBoxes();
							} else {
								$('#noData').show();
								$('#noNet').hide();
								api.toast({
									msg : '暂无数据'
								});
								$('#checkboxes').html('');
							}
						} else {
							$('#noData').show();
							$('#noNet').hide();
							api.toast({
								msg : '您当前尚未管理班级，无对应数据'
							});
						}
					} else {
						$('#noData').hide();
						$('#noNet').show();
						api.toast({
							msg : '获取班级列表失败'
						});
					}
				});
			}

			//设置第一个班数据
			function showFirstClass(data) {
				$("#className").text(data.classname);
				classid = data.id;
			}

			//设置第一个计划数据
			function showFirstPlanData(data) {
				$("#planName").text(data.planname);
				planid = data.id;
				grabClassData();
			}

			function setupPlanClick() {
				$("#dropdownPlanList .plan_cell").unbind('click');
				$("#dropdownPlanList .plan_cell").click(function() {
					$('#dropdownPlanList').toggle();
					$("#planName").text($(this).text());
					//重置班级列表数据
					$("#className").text('全部');
					//重置班级id
					classid = 'normal';
					planid = $(this).attr('id');
					grabClassData();
				});
			}

			//设置班级事件
			function setupClassClick() {
				$("#dropdownClassList .class_cell").unbind('click');
				$("#dropdownClassList .class_cell").click(function() {
					$('#dropdownClassList').toggle();
					$("#className").text($(this).text());
					classid = $(this).attr('id');
					grabClassData();
				});
			}

			//拼接班级数据
			function classHtmlStr(data) {
				return '<li id="' + data.class_id + '" class="mui-table-view-cell class_cell" >' + data.classname + '</li>';
			}

			function planHtmlStr(data) {
				return '<li id="' + data.id + '" class="mui-table-view-cell plan_cell" >' + data.planname + '</li>';
			}

			//获取班级学生列表
			function grabClassStudentsData() {
				showProgressFrame();
				var params = {
					class_id : classid,
					uid : $api.getStorage('cfnetppuid'),
					jid : $api.getStorage('cfnetppjid')
				};
				cfnetppPOST(urlStudentlist, params, true, function(data, status) {
					api.hideProgress();
					if (status == 'success') {
						if (data.status == 1) {
							//					var students = data.json;
							var dataArray = data.json;
							var students = dataArray.lst;
							if (students != '' && students.constructor == Array && students.length > 0) {
								$('#noData').hide();
								$('#noNet').hide();
								currentStudents = students;
								var studentsHtmlStr = '';
								for (var i = 0; i < students.length; i++) {
									var studentData = students[i];
									studentsHtmlStr += studentHtmlString(studentData, i);
								}
								$('#checkboxes').html(studentsHtmlStr);
								setupCheckBoxes();
							} else {
								$('#noData').show();
								$('#noNet').hide();
								api.toast({
									msg : '暂无数据'
								});
							}
						} else {
							$('#noData').show();
							$('#noNet').hide();
							api.toast({
								msg : '获取学生列表失败'
							});
						}
					} else {
						$('#noData').hide();
						$('#noNet').show();
						api.toast({
							msg : '获取学生列表失败'
						});
					}
				});
			}

			function setupCheckBoxes() {
				$("#checkdeAll").prop("checked", false);
				$("#studentNum").text('0');
				//单选
				$("#checkboxes .mui-table-view-cell").unbind('click');
				$("#checkboxes .mui-table-view-cell").click(function() {
					var len = $("#checkboxes input:checkbox:checked").length;
					//选中个数
					if (len < $("#checkboxes input[type=checkbox]").length) {
						$("#checkdeAll").prop("checked", false);
					}
					$("#studentNum").text(len)// 显示选中个数
				});
			}

			function prepareData() {
				uid = $api.getStorage('cfnetppuid');
				jid = $api.getStorage('cfnetppjid');
				// 点击出下拉菜单
				$("#dropdownPlanBtn").click(function() {
					$('#dropdownPlanList').toggle();
				})
				$("#dropdownClassBtn").click(function() {
					$('#dropdownClassList').toggle();
				})
				//全选
				$("#checkdeAll").click(function() {
					if (this.checked) {
						$("#checkboxes input[type=checkbox]").prop("checked", true);
					} else {
						$("#checkboxes input[type=checkbox]").prop("checked", false);
					}
					var len = $("#checkboxes input:checkbox:checked").length;
					//选中的个数
					$("#studentNum").text(len)// 显示选中个数
				})
				//提交绑定事件
				$('#submit').click(function() {
					var dataindexs = getUserIds();
					if (dataindexs == null || dataindexs == '' || dataindexs == undefined || dataindexs.constructor != Array || dataindexs.length == 0) {
						api.toast({
							msg : '请选择学生后再提交'
						});
						return;
					}
					var selectedStuIds = new Array();
					var selectedStuName=new Array();
					var selectedStuDatas = new Array();
					for (var i = 0; i < dataindexs.length; i++) {
						var index = parseInt(dataindexs[i]);
						var studentData = currentStudents[index];
						var stuId = parseInt(studentData.uid);
						var stuName = studentData.rename1;
						selectedStuIds.push(stuId);
						selectedStuName.push(stuName);
						selectedStuDatas.push({
							studentid : stuId,
							studentname : stuName
						});
					}
					
					SendBehaviorTrajectoriesNotifi1('1', '批量更改学生实习状态页', '113',api.pageParam.sourceurl, api.pageParam.sourcetitle, window.location.pathname,  document.title);
					api.openWin({useWKWebView:true,
						name : 'TrainChangeStatusSetPracticeTime',
						url : 'TrainChangeStatusSetPracticeTime.html',
						pageParam : {
							// classid : classid,
							planid : planid,
							students : selectedStuIds,
							selectedStuName:selectedStuName.toString(),
								sourceurl : window.location.pathname,
					sourcetitle : document.title
						}
					});
				});
			}

			function getUserIds() {
				var $value = [];
				$('#checkboxes').find('input').each(function(i) {
					if (this.checked == true) {
						$value.push($(this).attr('dataindex'));
					}
				});
				return $value;
			}

			function studentHtmlString(data, i) {
				var userid = data.uid;
				var uname = data.rename1;
				var corpname = data.corp_name;
				var ustatus;
				var ustatusStr = '';
				var ustatusClass = '';
				// if (pageType == 0) {
				// 	ustatus = data.is;
				// 	if (ustatus == 0) {
				// 		ustatusStr = '未实习';
				// 		ustatusClass = 'sxtype0';
				// 		// ustatusClass = 'studentbtn0';
				// 	}else if(ustatus == 1){
				// 		ustatusStr = '实习中';
				// 		ustatusClass = 'sxtype1';
				// 		// ustatusClass = 'studentbtn1';
				// 	}else if(ustatus == 2){
				// 		ustatusStr = '实习结束';
				// 		ustatusClass = 'sxtype2';
				// 		// ustatusClass = 'studentbtn2';
				// 	}else if(ustatus == 3){
				// 		ustatusStr = '未结业';
				// 		ustatusClass = 'sxtype3';
				// 		// ustatusClass = 'studentbtn3';
				// 	}else if(ustatus == 4){
				// 		ustatusStr = '已结业';
				// 		ustatusClass = 'sxtype4';
				// 		// ustatusClass = 'studentbtn4';
				// 	}
				// }
				//实习状态
				var sxtypes = data.sxtypes;
				//				alert(sxtypes);
				if (sxtypes == 0) {
					ustatusStr = '顶岗实习';
					ustatusClass = 'sxtype0';
				} else if (sxtypes == 1) {
					ustatusStr = '认识实习';
					ustatusClass = 'sxtype1';
				} else if (sxtypes == 2) {
					ustatusStr = '跟岗实习';
					ustatusClass = 'sxtype2';
				}
				if (corpname == null || typeof (corpname) == undefined) {
					corpname = '暂无实习单位';
				}
				return '<li class="mui-table-view-cell mui-checkbox mui-media">' + '<a href="javascript:;">' + '<img class="mui-media-object mui-pull-left" src="../../image/icon_man.png">' + '<div class="mui-media-body top_15">' + uname +
				// '<img class="gender" src="../../image/icon_boy.png" alt="">	'+
				'<span class="' + ustatusClass + '  ">' + ustatusStr + '</span>'
				// +  '<p class="mui-ellipsis">实习单位：' + corpname +
				//				 '</p>'
				+ '</div>' + '</a>' + '<input dataindex="' + i + '" name="checkbox2" value="Item 1" type="checkbox" class="">' + '</li>';
				//				return '<li class="mui-table-view-cell mui-checkbox mui-media">'+
				//					'<a href="javascript:;">
				//					'<img class="mui-media-object mui-pull-left" src="../../image/icon_man.png">'+
				//					'<div class="mui-media-body top_10">'+
				//						uname +
				//						'<span class="' + ustatusClass + '  btnpos right_15"> '+
				//						ustatusStr+
				//						'</span>'+
				//					'</div>' +
				//					'</a>'+
				//					'<input name="checkbox2" value="Item 1" type="checkbox" class="top_10">'+
				//				'</li>';
			}

			function showProgressFrame() {
				api.showProgress({
					style : 'default',
					animationType : 'fade',
					title : '加载中...',
					text : '请稍候...',
					modal : false
				});
			}

			//    function setupType(){
			// 	var pageParam = api.pageParam;
			// 	pageType = pageParam.type;
			// 	if (pageType == 1) {//展示实习企业学生
			// 		$('#dropdownPlanBtn').hide();
			// 		$('#dropdownClassBtn').hide();
			// 		loadCompanyStu(pageParam.cid);
			// 	}else{
			// 		$('#dropdownPlanBtn').hide();
			// 		$('#dropdownClassBtn').hide();
			// 		prepareData();
			// 		grabClassData();
			// 	}
			// }
			// //加载企业实习学生
			// function loadCompanyStu(cid){
			// 	showProgressFrame();
			// 	var params = {
			// 		cid : cid,
			// 		uid : $api.getStorage('cfnetppuid')
			// 	};
			// 	cfnetppPOST(urlCompanyStuList,params,true,function(data, status){
			// 		api.hideProgress();
			// 		if (status == 'success') {
			// 			if (data.status == 1) {
			// 				var students = data.json;
			// 				if (students.constructor == Array && students.length > 0) {
			// 					$('#noData').hide();
			// 					$('#noNet').hide();
			// 					currentStudents = students;
			// 					var studentsHtmlStr = '';
			// 					for (var i = 0; i < students.length; i++) {
			// 						var studentData = students[i];
			// 						studentsHtmlStr += studentHtmlString(studentData, i);
			// 					}
			// 					$('#checkboxes').html(studentsHtmlStr);
			// 					setupCheckBoxes();
			// 				}else{
			// 					$('#noData').show();
			// 					$('#noNet').hide();
			// 					api.toast({
			// 					    msg: '加载学生列表失败'
			// 					});
			// 				}
			// 			}else{
			// 				$('#noData').show();
			// 				$('#noNet').hide();
			// 				api.toast({
			// 				    msg: '加载学生列表失败'
			// 				});
			// 			}
			// 		}else{
			// 			$('#noData').hide();
			// 			$('#noNet').show();
			// 			api.toast({
			// 			    msg: '加载学生列表失败'
			// 			});
			// 		}
			// 	});
			// }
		</script>
	</body>
</html>
